package com.sgb.kjwl.view.ui.activity.transport;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.TypedValue;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;

import com.fondesa.recyclerviewdivider.DividerDecoration;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityFreightPaymentVoucherBinding;
import com.sgb.kjwl.view.constant.RouterKey;
import com.sgb.kjwl.view.ui.adapter.transport.CertificateImageAdapter;
import com.sgb.kjwl.view.widget.transport.ImagePreviewDialog;

import java.util.ArrayList;
import java.util.List;

/**
 * Describe:    运费支付凭证
 * Author:  yangLei
 * Date:    2021/7/6
 */
public class FreightPaymentVoucherActivity extends AppActivity {

    private ActivityFreightPaymentVoucherBinding mBinding;
    //图片列表
    private List<String> mList;
    private CertificateImageAdapter mAdapter;

    public static void start(Context context, List<String> images) {
        Intent intent = new Intent(context, FreightPaymentVoucherActivity.class);
        intent.putStringArrayListExtra(RouterKey.DATA, new ArrayList<>(images));
        context.startActivity(intent);
    }

    @Override
    protected void init() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_freight_payment_voucher);
        mBinding.setLifecycleOwner(this);
//        mBinding.actionBar.setTitle("运费支付凭证");
//        mBinding.credentialsHint.setText("运费支付凭证由司机确认线下收款时上传");
        initRecycler();
        initEvent();
    }

    private void initRecycler() {
        mList = new ArrayList<>();
        //设置数据
        List<String> images = getIntent().getStringArrayListExtra(RouterKey.DATA);
        if (images != null) {
            mList.addAll(images);
        }
        mAdapter = new CertificateImageAdapter(mList);
        mBinding.rvReceiptCertificate.setLayoutManager(new GridLayoutManager(this, 4));
        DividerDecoration.builder(this)
                .color(Color.TRANSPARENT)
                .size(10, TypedValue.COMPLEX_UNIT_DIP)
                .build()
                .addTo(mBinding.rvReceiptCertificate);
        mAdapter.bindToRecyclerView(mBinding.rvReceiptCertificate);
    }

    private void initEvent() {
        mBinding.actionBar.setOnBackClickListener(view -> finish());
        mAdapter.setOnItemClickListener((adapter, view, position) -> ImagePreviewDialog.newInstance(mList.get(position)).show(this));
    }
}
